package com.itzhigui.order.controller;

import com.itzhigui.common.entity.Goods;
import com.itzhigui.order.service.GoodsService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

/**
 * 商品订单信息
 *
 * @author java1412
 * @since 2023-10-29 17:43:36
 */
@RestController
@RequestMapping("/api/v1/goods_order")
public class OrderController {

//    @Resource
//    private RestTemplate restTemplate;
//
//    @RequestMapping("/getGoods")
//    public Object save(int goodsId) {
////        Goods goods = restTemplate.getForObject("http://localhost:6001/api/v1/goods/findByGoodsId?goodsId=" + goodsId,
////                Goods.class);
//        Goods goods = restTemplate.getForObject("http://mall-goods/api/v1/goods/findByGoodsId?goodsId=" + goodsId,
//                Goods.class);
//        return goods;
//    }

    // 注入GoodsSerivce
    @Resource
    private GoodsService goodsService;

    @RequestMapping(value = "/getGoodsByFeign")
    public Object getGoodsByFeign(int goodsId) {
        return goodsService.findByGoodsId(goodsId);
    }

    @RequestMapping(value = "/findClusterName")
    public Object findClusterName() {
        // 循环10次，测试是哪种负载均衡策略
        for (int i = 0; i < 10; i++) {
            System.out.println(goodsService.findClusterName());
        }
        return "执行结束";
    }
}
